<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>监听器的使用</title>
</head>
<body>
    <script src="js/vue.js"></script>
    <div id="app">

        <p>{{Value}}</p>
        <button @Click="change()">button</button>
        <p>{{price}}</p>
        <button @Click="changePrice()">button</button>
        <p>比原价贵了{{expensive元}}</p>
    </div>
    <script>
        let app = new Vue({
            el:'#app',
            data:{
                Value:100,
                price:100,
                expensive:0
            },
            methods:{
                change(){
                    this.value ++
                },
                changePrice(){
                    this.price += 10
                }
            },
            watch:{//监听器
                //datanme: function(){}datanamen与监听的数据名字相同
                value(newValue,oldValue){
                    console.log("值发生了变化");
                    console.log("new",newValue);
                    console.log("old",oldValue);
                },
                price(newValue,oldValue){
                    //现价-原价
                    this.expensive = newValue-this.price
                    console.log("oldValue:",oldValue);
                    console.log("thisprice",this.price);
                    console.log(this.expensive);
                }
            }
        })
    </script>
</body>